﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class caseedit : System.Web.UI.Page
{
    public string SqlClass = "";
	public string strygcname,strygcheckcode,strbgcname,strbgcheckcode;
	public string strtel,strcasecode,strcasetitle,strjudge,straddtime,strccontent,strcstatus;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"]==null)
		{
			Response.Write("<script>alert('你没有管理员权限，禁止访问！');history.back();</script>");
		}
		if (!Page.IsPostBack)
        {
            string id = Request.QueryString["id"];
			DataSet dss = Socut.Data.ExecuteDataSet("select judgename,id from web_judge where isused=0 order by orderno");
				this.DropDownList1.DataSource=dss.Tables[0].DefaultView; 
				this.DropDownList1.DataTextField="judgename"; 
				this.DropDownList1.DataValueField = "id"; 
				this.DropDownList1.DataBind(); 
				
            if (!string.IsNullOrEmpty(id))
            {
                HiddenField1.Value = Request.QueryString["id"];
				DataSet ds = Socut.Data.ExecuteDataSet("select * from web_case where id=" + id);
                casetitle.Text = ds.Tables[0].Rows[0]["casetitle"].ToString();
				casecode.Text = ds.Tables[0].Rows[0]["casecode"].ToString();
				ygcname.Text = ds.Tables[0].Rows[0]["ygname"].ToString();
				ygcheckcode.Text = ds.Tables[0].Rows[0]["ygcheckcode"].ToString();
				bgcname.Text = ds.Tables[0].Rows[0]["bgname"].ToString();
				bgcheckcode.Text = ds.Tables[0].Rows[0]["bgcheckcode"].ToString();
				string jname = ds.Tables[0].Rows[0]["judge"].ToString();
                //Response.Write(jname);
                //Response.End();
                this.DropDownList1.Items.FindByText(jname).Selected=true;
				tel.Text = ds.Tables[0].Rows[0]["tel"].ToString();
				addtime.Text = Convert.ToDateTime(ds.Tables[0].Rows[0]["addtime"].ToString()).ToShortDateString();
				ccontent.Text = ds.Tables[0].Rows[0]["content"].ToString();
				cstatus.SelectedValue = ds.Tables[0].Rows[0]["status"].ToString();
            }
			else
			{
    			Response.Write("<script>alert('操作错误');history.back();</script>");
				
            }
			
        }
    }
    private void ShowData()
    {
    }
        protected void Button1_Click(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(HiddenField1.Value))//回复
            {
                strcasetitle=casetitle.Text.ToString();
				strcasecode=casecode.Text.ToString();
				strygcname=ygcname.Text.ToString();
				strygcheckcode=ygcheckcode.Text.ToString();
				strbgcname=bgcname.Text.ToString();
				strbgcheckcode=bgcheckcode.Text.ToString();
                strjudge = judge.SelectedValue.ToString();
				strtel=tel.Text.ToString();
				straddtime=Convert.ToDateTime(addtime.Text.ToString()).ToShortDateString();
				strccontent=ccontent.Text.ToString();
				strcstatus=cstatus.SelectedValue.ToString();

				try
                {
                    Socut.Data.ExecuteNonQuery("update [web_case] set casetitle='" + strcasetitle + "',casecode='" + strcasecode +"',ygname='" + strygcname + "',ygcheckcode='" + strygcheckcode +"',bgname='" + strbgcname + "',bgcheckcode='" + strbgcheckcode +"',judge='" + strjudge + "',tel='" + strtel +"',addtime='" + straddtime + "',content='" + strccontent +"',status=" + strcstatus + " where id=" + HiddenField1.Value);
                    Response.Write("<script>alert('恭喜，操作成功！');location.href='case.aspx';</script>");
					Response.End();
                }
                catch (Exception Err)
                {
                    Response.Write("<script>alert('操作错误');history.back();</script>");
					Response.End();
                }
            }
            else//错误
            {

                Response.Write("<script>alert('操作错误');history.back();</script>");
					Response.End();


            }
            //Response.Write(AllLimit);
        }
	
	protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        tel.Text = checktel(DropDownList1.SelectedItem.ToString());
    }
    public string checktel(string strjudge)
    {
        string judgestr = strjudge;
        DataSet ds = Socut.Data.ExecuteDataSet("select * from web_judge where judgename='" + judgestr + "'");
        string strtel = ds.Tables[0].Rows[0]["tel"].ToString();
        return strtel;
    }

}
